package com.qingfeng.medical.controller.admin.infomation;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qingfeng.medical.base.controller.BaseController;
import com.qingfeng.medical.base.log.annotation.Log;
import com.qingfeng.medical.base.log.enums.BusinessType;
import com.qingfeng.medical.base.result.Result;
import com.qingfeng.medical.biz.information.domain.dto.UserInfoUpdateDTO;
import com.qingfeng.medical.biz.information.domain.entity.UserInfo;
import com.qingfeng.medical.biz.information.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 前台用户表
 *
 * @author 清风学Java
 * @date 2023-04-21 23:03:12
 */
@Api(tags = "用户表管理")
@RestController
@RequestMapping("/admin/info/userInfo")
@Validated
public class UserInfoController extends BaseController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "分页查询用户信息", notes = "分页查询用户信息")
    @GetMapping("/list")
    @Log(title = "前台用户管理", businessType = BusinessType.SELECT, message = "分页查询用户信息")
    public Result<Page<UserInfo>> userInfoList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @RequestParam("page") Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @RequestParam("limit") Long limit,
            @ApiParam(name = "certificatesType", value = "证件类型", required = false)
            @RequestParam("certificatesType") String certificatesType,
            @ApiParam(name = "authStatus", value = "认证状态", required = false)
            @RequestParam("authStatus") Integer authStatus) {
        Page<UserInfo> userInfoPage = userInfoService.userInfoPage(
                new Page<UserInfo>(page, limit),
                certificatesType, authStatus
        );
        return Result.ok(userInfoPage);
    }

    @ApiOperation(value = "用户认证", notes = "用户认证")
    @PutMapping("/auth")
    @Log(title = "前台用户管理", businessType = BusinessType.UPDATE, message = "用户认证")
    public Result userAuth(@Validated @RequestBody UserInfoUpdateDTO userInfoUpdateDTO) {
        userInfoService.userAuth(userInfoUpdateDTO);
        return Result.ok();
    }
}
